package net.bithappens.hnqe.graph;

import java.net.URI;
import java.util.Calendar;
import java.util.Date;

import net.bithappens.hnqe.IllegalParamException;

public abstract class GraphElement {

	private URI uri;
	
	private Calendar lease;

	
	
	public GraphElement(URI uri) throws IllegalParamException{
		if(uri == null || uri.toString().isEmpty()){
			throw new IllegalParamException("the url must not be null or empty");
		}
		
		this.uri = uri;
	}
	
	public GraphElement(URI uri, Date lease) throws IllegalParamException{
		if(uri == null || uri.toString().isEmpty()){
			throw new IllegalParamException("the url must not be null or empty");
		}
		
		this.uri = uri;
		
		if(lease != null){
			this.lease = Calendar.getInstance();
			this.lease.setTime(lease);
		}		
	}
	
	
	public URI getUri() {
		return uri;
	}

	public Calendar getLease() {
		return lease;
	}
	
	public void setLease(Date lease){
		if(lease != null){
			this.lease = Calendar.getInstance();
			this.lease.setTime(lease);
		}	
	}
	
	public abstract String getTypeId();

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uri == null) ? 0 : uri.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GraphElement other = (GraphElement) obj;
		if (uri == null) {
			if (other.uri != null)
				return false;
		} else if (!uri.equals(other.uri))
			return false;
		return true;
	}
}
